import { get, post, put, del } from "../utils/request";
import type {
  Article,
  CreateArticleDto,
  UpdateArticleDto,
} from "../types/article";
import type { ResponseData } from "../utils/request";

// 文章相关接口
export const articleApi = {
  list: () => get<ResponseData<Article[]>>("/api/articles"),

  detail: (id: string) => get<ResponseData<Article>>(`/api/articles/${id}`),

  create: (data: CreateArticleDto) =>
    post<ResponseData<Article>>("/api/articles", data),

  update: (id: string, data: UpdateArticleDto) =>
    put<ResponseData<Article>>(`/api/articles/${id}`, data),

  delete: (id: string) => del<ResponseData<void>>(`/api/articles/${id}`),
};

// 用户相关接口
export const userApi = {
  login: (data: { username: string; password: string }) =>
    post<ResponseData<{ token: string }>>("/api/auth/login", data),

  profile: () =>
    get<ResponseData<{ name: string; email: string }>>("/api/auth/profile"),
};

// 标签相关接口
export const tagApi = {
  list: () => get<ResponseData<string[]>>("/api/tags"),
  create: (tag: string) => post<ResponseData<string>>("/api/tags", { tag }),
};
